# -*- coding: utf-8 -*-
from selenium.webdriver.common.by import By

from web_pom_project.base.WebKeys import WebKeys


class SearchPage(WebKeys):
    def search_book(self,book,url=None):
        if url:
            self.open(url)
        # 功能 搜索书籍的目的是为了知道 我的列表有没有这个本书
        self.locator_with_wait(By.ID,"searchKey").send_keys(book)
        self.locator_with_wait(By.ID,"btnSearch").click()

        # 加载我的书籍列表
        book_list=self.locator_with_wait(By.ID,"bookList")
        # 获得书
        book_rows=book_list.find_elements(By.TAG_NAME,"tr")
        # 获得书名
        book_found=[]
        for row in book_rows:
            # 循环了每一本书
            book_name_ele=row.find_element(By.CSS_SELECTOR,".name>a")
            book_name=book_name_ele.text
            book_found.append(book_name)
        return book_found
        # 断言  我输入的书名 在不在 书籍列表

